package com.xes.online.controller;

import com.xes.online.entities.CommonResult;
import com.xes.online.service.TalSendService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.Message;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @program: scs-demo
 * @description:
 * @author: pkn
 * @create: 2020-06-28 15:47
 */
@RestController
@Slf4j
public class TalSendController {

    @Resource
    private TalSendService talSendService;


    @PostMapping("/msg/send")
    public CommonResult send(String destination, String payload) {

        Message message = talSendService.send(destination, payload);
        log.info("发送消息：" + message);

        if (message != null) {
            return new CommonResult(200, "发送消息成功", message);
        } else {
            return new CommonResult(444, "发送消息失败", null);
        }
    }

    @PostMapping("/msg/sendWithTag")
    public CommonResult sendWithTag(String destination, String payload, String tag) {

        Message message = talSendService.sendWithTag(destination, payload, tag);
        log.info("发送消息：" + message);

        if (message != null) {
            return new CommonResult(200, "发送消息成功", message);
        } else {
            return new CommonResult(444, "发送消息失败", null);
        }
    }

    @PostMapping("/msg/sendObject")
    public <T> CommonResult sendObject(String destination, T msg) {

        Message message = talSendService.sendObject(destination, msg);
        log.info("发送消息：" + message);

        if (message != null) {
            return new CommonResult(200, "发送消息成功", message);
        } else {
            return new CommonResult(444, "发送消息失败", null);
        }
    }


}
